import type { Metadata } from "next";
import "./globals.css";
import Script from "next/script";
import { Toaster } from "@/components/ui/sonner";
import NextTopLoader from "nextjs-toploader";
import { alicdnScript } from "@/config/script";
import PageTransition from "@/components/PageTransition";

export const metadata: Metadata = {
  title: "cc的博客",
  description: "这是cc的博客",
};

export default function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  return (
    <html lang="en">
      <Script src={alicdnScript} />
      <Script
        dangerouslySetInnerHTML={{
          __html: `
            (function() {
            const UI_WIDTH = 1280;
            const baseFontSize = 16;
            function setRootFontSize() {
                const width = document.documentElement?.clientWidth;
                if(width > UI_WIDTH || width < 753) {
                return document.documentElement.style.fontSize = '16px';
                }
                const fontSize = ((width / UI_WIDTH) * baseFontSize).toFixed(4);
                document.documentElement.style.fontSize = fontSize + 'px';
            }
            setRootFontSize();
            window.addEventListener('resize', setRootFontSize);
            })();
        `,
        }}
      />
      <body>
        <PageTransition>
          <NextTopLoader showSpinner={false} />
          <Toaster position="top-center" />
          {children}
        </PageTransition>
      </body>
    </html>
  );
}
